Update(09/28): 已完成 section 4,5
晚上剛回台北QQ
這個筆記還蠻個人的,對別人來說沒太大參考價值
先看到 Section 3,明天先補上 4 5
照原定計畫看把 MySQL Basics 看過去,
雖然本來就會一些,但還是有收穫。
本篇包含 5 sections:
select now()
select 1+1
具體什麼時候會用到呢
order by col1 desc, col2 asc
field
function,可以指定一個 list,並讓結果照著此 list 的順序排field(要找的string, str1, str2, str3...): 例如 field('a', 'a', 'b') 回 1,field('b', 'a', 'b') 回 2
SELECT
orderNumber, status
FROM
orders
ORDER BY FIELD(status,
'In Process',
'On Hold',
'Cancelled',
'Resolved',
'Disputed',
'Shipped');
為什麼要能夠與 null 比較?背後的語意是什麼?
cast
SELECT
orderNumber,
requiredDate,
status
FROM
orders
WHERE
requireddate BETWEEN
CAST('2003-01-01' AS DATE) AND
CAST('2003-01-31' AS DATE);
%
0或多,_
1ESCAPE
clause 來指定逃脫字元選 含有 _20 的 records
SELECT
productCode,
productName
FROM
products
WHERE
productCode LIKE '%$_20%' ESCAPE '$';
LIMIT [offset,] row_count;
offset 由 0 開始,包含。從不同表拿 Column,通常兩張表之間有 foreign keys 關聯
from table as t
select column as c from table
on t1.column = t2.column
相等於 using (column)
,括號不能省略不懂括號的意義?
WHERE ordernum=123
FROM orders o LEFT JOIN orderDetails d ON o.ordernum = d.ordernum and o.ordernum=123
實際應用還不是很有感覺
DESC
/ASC
having 或是 where 可以達到類似的效果的時候,用哪個比較快呢?
SELECT
select_list
FROM
table_name
GROUP BY
c1, c2, c3 WITH ROLLUP;
group by c1, c2 with rollup
grouping sets如下先知道,以後有需要再細讀
SELECT
IF(GROUPING(orderYear),
'All Years',
orderYear) orderYear,
IF(GROUPING(productLine),
'All Product Lines',
productLine) productLine,
SUM(orderValue) totalOrderValue
FROM
sales
GROUP BY
orderYear ,
productline
WITH ROLLUP;